package com.system.permissiondemo.controller;

import com.system.permissiondemo.common.BaseResult;
import com.system.permissiondemo.exception.CustomizeErrorCode;
import com.system.permissiondemo.exception.CustomizeException;
import com.system.permissiondemo.param.TestVo;
import com.system.permissiondemo.util.BeanValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.MapUtils;

import java.util.Map;

@Controller
@RequestMapping(value = "/test")
@Slf4j
public class TestController {

    @RequestMapping(value = "/hello.json",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult hello(){
        log.info("test");
        throw new CustomizeException(CustomizeErrorCode.QUESTION_NOT_FOUND);
        //return BaseResult.ok();
    }
    @RequestMapping(value = "/vali.json",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult vali(TestVo vo){
        log.info("vo");
        /*try {
            Map<String,String> map = BeanValidator.validateObject(vo);
            if (!MapUtils.isEmpty(map)){
                for (Map.Entry<String,String> entry:map.entrySet()){
                    log.info("{}-->{}",entry.getKey(),entry.getValue());
                }
            }
        }catch (Exception e){

        }*/
        BeanValidator.check(vo);
        return BaseResult.ok();
    }
}
